package dongshi.daddy.observer.v2.subject;

import dongshi.daddy.observer.v2.observer.OldPeopleObserver;

import java.util.ArrayList;
import java.util.List;

// 物美超市主题类
// 如果是有其它超市的话，可以类比实现
public class WuMeiSubject implements SuperMarketSubject {
    private List<OldPeopleObserver> oldPeopleObservers = new ArrayList<>();

    @Override
    public void addOldPeopleObserver(OldPeopleObserver oldPeopleObserver) {
        oldPeopleObservers.add(oldPeopleObserver);
    }

    @Override
    public void removeOldPeopleObserver(OldPeopleObserver oldPeopleObserver) {
        oldPeopleObservers.remove(oldPeopleObserver);
    }

    @Override
    public void notify(String productName) {
        oldPeopleObservers.forEach(oldPeopleObserver -> oldPeopleObserver.action(productName));
    }
}
